<!DOCTYPE html>
<?php
include_once '../objects/person.php';
include_once '../actions/listUser.php';
include_once '../actions/actionResult.php';

session_start();
if (!isset($_SESSION['user'])) {
    header("location: ../../index.php");
} else {
    $user = $_SESSION['user'];
    if ($user->getRolperson() == 0) {
        header("location: ../../index.php");
    }
}
$lists = new listUser();
$actResult = new actionResult();
if (!isset($_GET['batch']) || ($_GET['batch'] == -1)) {
    echo '<div></div> ';
} else {
    $batch = $_GET['batch'];
    $food = $lists->foodcod($_GET['batch']);
    $growthU = $actResult->growthUser($batch, $food);
    ;

    function consultProlog($file, $weigth, $age, $food) {
        $cmd = "\"C:/Program Files/swipl/bin/swipl.exe\" -l " . $file . " -g evaluar($weigth,$age,$food,R),halt";
        $output = shell_exec($cmd); //conexion de swi prolog y php
        return $output;
    }

    $namefile = $growthU->getNamerace(); //llamar la raza       
    $file = "../../rules/" . $namefile . ".pl"; //este no se va a recibir por parametro  
    $R1 = consultProlog($file, $growthU->getWeightpreweaning(), $growthU->getAgepreweaning(), $growthU->getFoodname());
    $R2 = consultProlog($file, $growthU->getWeightpreceba(), $growthU->getAgepreceba(), $growthU->getFoodname());
    $R3 = consultProlog($file, $growthU->getWeightceba(), $growthU->getAgeceba(), $growthU->getFoodname());
    $pd = $actResult->prompt($R1);
    $pc = $actResult->prompt($R2);
    $c = $actResult->prompt($R3);
    $pdr = explode('$', $pd);
    $pcr = explode('$', $pc);
    $cr = explode('$', $c);
}
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>* SEPC *</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script language="JavaScript" src="../../js/validations.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="../../style/bootstrap.css">
        <link rel="stylesheet" type="text/css" href="../../style/bootstrap-responsive.css">
        <link rel="stylesheet" type="text/css" href="../../style/styles.css">
    </head>
    <body>
        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </a>
                    <a href="../../index.php" class="brand"><img src="../../img/sepc_logo.png" alt=""></a>
                    <div class="nav-collapse">
                        <ul class="nav">
                            <li class="nav-header"><h3>Menu Usuario :: Resultados</h3></li>
                            <li><a></a></li><li><a></a></li><li><a></a></li><li><a></a></li>
                            <li><a></a></li><li><a></a></li><li><a></a></li>
                            <li class="right"><a href="menuUser.php"><?php echo $user->getMail(); ?></a></li>                          
                        </ul>
                        <form class="navbar-form pull-right" name="" action="../closeConexion.php" method="post" >
                            <button type="submit" class="btn btn-danger"><i class="icon-remove-sign  icon-white"></i> Cerrar Session</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <br>
        <div class="container">
            <ul class="pager">
                <li class="previous">
                    <a class="badge-success" href="findResult.php"><i class="icon-arrow-left icon-white"></i></a>
                </li>
                <li class="next disabled">
                    <a class="badge-success" href="#"><i class="icon-arrow-right icon-white"></i></a>
                </li>
            </ul>
            <div><?php
                if (!isset($_GET['batch']) || ($_GET['batch'] == -1)) {
                    echo '<div class="alert alert-warning" align="center"><strong>Informacion!</strong>  No ha escogido ningun lote. </div> ';
                } else {
                    echo '<div class="row-fluid"><div class="span7"><div>';
                    echo'<h4>Resultado Etapa Pre-Deste</h4><small><p>';
                    echo $pdr[0]; echo "<br>";
                    echo '</p></small><h4>Resultado Etapa Pre-Ceba</h4><small><p>';
                    echo $pcr[0]; echo "<br>";
                    echo '</p></small><h4>Resultado Etapa Ceba</h4><small><p>';
                    echo $cr[0];
                    echo '<br>';
                    echo '<br>';
                    echo $cr[2];
                    echo "<br>";
                    echo "<br>";
                    echo $cr[3];
                    echo '</p></small></div></div><div class="span5"><div class="hero-unit">
                        <div align="center"><img src="graph.php?b=' . $batch . '&f=' . $food . '"/></div>';
                    echo '</div></div></div>';
                }
                ?>  
            </div>
            <footer class="footer">
                <div class="container">
                    <small> 
                        <img src="../../img/unicor_logo.png">
                        <strong>    Universidad de Cordoba. Facultad de Ingen&iacute;erias :: Departamento de Ingen&iacute;eria de Sistemas y Telecomunicaciones</strong>
                        <br>
                        Dise&ntilde;ado y Desarrollado por: Mar&iacute;a Alejandra Teher&aacute;n &amp; Daniela Mu&ntilde;oz De La Rosa &copy;
                    </small>
                </div>
            </footer>
        </div>
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/bootstrap.js"></script>
        <script type="text/javascript" src="js/bootstrap-collapse.js"></script>
    </body>
</html>